package com.dd.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Random;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import com.dd.action.form.MainForm;
import com.dd.dao.DdCommentDAO;
import com.dd.dao.DdDeliveryDAO;
import com.dd.dao.DdOrderDAO;
import com.dd.dao.DdShopDAO;
import com.dd.dao.DdUserDAO;
import com.dd.dao.DdUserpayDAO;
import com.dd.entity.*;
import com.dd.service.ShopService;
import com.dd.util.DateStrFormat;
import com.dd.util.PageList;
import com.dd.util.UpFile;

public class ShopAction extends BaseAction {
	private int REFLASH = 200;

	public ActionForward addcomment(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		PrintWriter out = response.getWriter();
		try {
			int shopid = Integer.parseInt(request.getParameter("shopid"));
			// DdShop ds = new DdShop();
			DdShop ds = this.getDdShopDAO().findById(shopid);
			if (ds.getCommentday().intValue() != DateStrFormat.getCurrentDay()) {
				ds.setComment(0);
				this.getDdShopDAO().saveOrUpdate(ds);

			}
			// 评论太多了
			if (ds.getComment().intValue() > 10) {
				out.print("{\"result\":\"2\"}");
				return null;
			}
			String comment = request.getParameter("comment");
			int service = Integer.parseInt(request.getParameter("service"));
			int taste = Integer.parseInt(request.getParameter("taste"));
			int environment = Integer.parseInt(request
					.getParameter("environment"));
			if (service > 5) {
				service = 5;
			}
			if (taste > 5) {
				taste = 5;
			}
			if (environment > 5) {
				environment = 5;
			}
			int totalscore = (service + taste + environment) / 3;
			ds.setComment(ds.getComment() + 1);
			ds.setCommentday(DateStrFormat.getCurrentDay());
			this.getDdShopDAO().saveOrUpdate(ds);
			DdComment dc = new DdComment();
			Integer logid = (Integer) request.getSession()
					.getAttribute("logid");// 网站用户是否已经登录
			if (logid != null) {
				dc.setUserid(logid);
				DdUser du = this.getDdUserDAO().findById(logid);
				dc.setUsername(du.getLogid());
			}
			dc.setComment(comment);
			dc.setShopid(shopid);
			dc.setService(service);
			dc.setEnvironment(environment);
			dc.setTaste(taste);
			dc.setTotalscore(totalscore);
			DdCommentDAO dcd = (DdCommentDAO) this.getBean("DdCommentDAO");
			dcd.saveOrUpdate(dc);
			out.print("{\"result\":\"1\"}");
			return null;
		} catch (Exception e) {
			out.print("{\"result\":\"0\"}");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward getcomment(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		PrintWriter out = response.getWriter();
		try {
			int shopid = Integer.parseInt(request.getParameter("shopid"));
			DdShop ds = this.getDdShopDAO().findById(shopid);
			DdCommentDAO dcd = (DdCommentDAO) this.getBean("DdCommentDAO");
			int pageno = 0;
			int pagesize = 10;
			if (request.getParameter("pageno") != null) {
				pageno = Integer.parseInt(request.getParameter("pageno"));
			}
			if (request.getParameter("pagesize") != null) {
				pagesize = Integer.parseInt(request.getParameter("pagesize"));
			}
			PageList pl = dcd.findByShopid(shopid, pageno, pagesize);
			StringBuffer sbf = new StringBuffer("{\"total\":\""
					+ pl.getTotalCount() + "\",\"comments\":[");
			for (int i = 0; i < pl.size(); i++) {
				DdComment dc = (DdComment) pl.get(i);
				if (i == 0) {
					sbf.append("{\"username\":\"" + dc.getUsername()
							+ "\",\"comtime\":\""
							+ DateStrFormat.getCurrentTimeZW(dc.getComdate())
							+ "\",\"totalscore\":\"" + dc.getTotalscore()
							+ "\",\"service\":\"" + dc.getService()
							+ "\",\"taste\":\"" + dc.getTaste()
							+ "\",\"environment\":\"" + dc.getEnvironment()
							+ "\",\"comment\":\""
							+ JsonCharFilter(dc.getComment()) + "\"}");
				} else {
					sbf.append(",{\"username\":\"" + dc.getUsername()
							+ "\",\"comtime\":\""
							+ DateStrFormat.getCurrentTimeZW(dc.getComdate())
							+ "\",\"totalscore\":\"" + dc.getTotalscore()
							+ "\",\"service\":\"" + dc.getService()
							+ "\",\"taste\":\"" + dc.getTaste()
							+ "\",\"environment\":\"" + dc.getEnvironment()
							+ "\",\"comment\":\""
							+ JsonCharFilter(dc.getComment()) + "\"}");
				}

			}
			sbf.append("]}");
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out.print("{\"result\":\"0\"}");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward newshop(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {
			DdShop ds = new DdShop();
			List list = this.getDdShopDAO().findByName(
					request.getParameter("name"));
			if (list.size() != 0) {
				sbf.append("<result>2</result></root>");
				return null;
			}
			this.getShopService().newShop(request, ds, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward editshop(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {

			DdShop ds = this.getDdShopDAO().findById(
					Integer.parseInt(request.getParameter("shopid")));
			if (ds == null) {
				sbf.append("<result>2</result></root>");
				return null;
			}
			this.getShopService().editShop(request, ds, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	// 新商家信息
	public ActionForward info(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		StringBuffer sbf = new StringBuffer();
		PrintWriter out = response.getWriter();
		try {

			DdShop ds = this.getDdShopDAO().findById(
					Integer.parseInt(request.getParameter("id")));
			if (ds == null) {
				sbf.append("{\"result\":\"2\"}");
				out.print(sbf.toString());
				return null;
			}
			this.getShopService().info(request, ds, sbf);
			ds.setHot(ds.getHot() + 1);
			this.getDdShopDAO().saveOrUpdate(ds);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}

	}

	// 新商家信息(简要)
	public ActionForward info2(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		StringBuffer sbf = new StringBuffer();
		PrintWriter out = response.getWriter();
		try {

			DdShop ds = this.getDdShopDAO().findById(
					Integer.parseInt(request.getParameter("id")));
			if (ds == null) {
				sbf.append("{\"result\":\"2\"}");
				out.print(sbf.toString());
				return null;
			}
			this.getShopService().info2(request, ds, sbf);
			ds.setHot(ds.getHot() + 1);
			this.getDdShopDAO().saveOrUpdate(ds);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}

	}

	public ActionForward shopinfo(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {

			DdShop ds = this.getDdShopDAO().findById(
					Integer.parseInt(request.getParameter("id")));

			if (ds == null) {
				sbf.append("<result>2</result></root>");
				out.print(sbf.toString());
				return null;
			}
			this.getShopService().shopInfo(request, ds, sbf);
			ds.setHot(ds.getHot() + 1);
			this.getDdShopDAO().saveOrUpdate(ds);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			System.out.println("error id:" + request.getParameter("id"));
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward remarkinfo(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {

			DdShop ds = this.getDdShopDAO().findById(
					Integer.parseInt(request.getParameter("id")));
			if (ds == null) {
				sbf.append("<result>2</result></root>");
				out.print(sbf.toString());
				return null;
			}
			sbf.append("<remarks>");
			PageList list = this.getDdOrderDAO().findAllRemark(ds.getId(), 1,
					10);
			for (int i = 0; i < list.size(); i++) {
				DdOrder dr = (DdOrder) list.get(i);
				String remark = "不错!";
				String name = "";
				if (dr.getRemark() != null
						&& dr.getRemark().indexOf("用户未及时确认订单成功") == -1) {
					remark = dr.getRemark();
				}

				DdUser du = this.getDdUserDAO().findById(dr.getUserid());
				if (du.getNickname() == null
						|| du.getNickname().trim().length() == 0) {
					name = du.getLogid();
				} else {
					name = du.getNickname();
				}
				sbf.append("<remark id=\"" + dr.getId() + "\" name=\"" + name
						+ "\" score=\"" + dr.getScore() + "\" date=\""
						+ DateStrFormat.getCurrentTime(dr.getConfirmdate())
						+ "\" remark=\"" + URLEncoder.encode(remark, "utf-8")
						+ "\"  />");
			}
			sbf.append("</remarks></root>");
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public boolean getIsRejectt(DdShop ds, String date, String loge) {
		boolean flag = false;
		try {
			date = date.substring(0, 13);
			int loge_i = 0;
			if (loge.equals("只订包厢")) {
				loge_i = 1;
			}
			flag = this.getDdShoprejectDAO().checkReject(ds.getId(), date,
					loge_i);
			return flag;
		} catch (Exception e) {
			// e.printStackTrace();
			return flag;
		}
	}

	// 餐厅定位类获取价格
	public ActionForward getprice(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {
			String date = request.getParameter("date");
			String loge = request.getParameter("loge");
			String orderdate1 = request.getParameter("orderdate1");
			String logetype = request.getParameter("logetype");
			String num = request.getParameter("num");
			DdShop ds = this.getDdShopDAO().findById(
					Integer.parseInt(request.getParameter("shopid")));
			if (ds == null) {
				sbf.append("<result>10.0</result></root>");
				out.print(sbf.toString());
				return null;
			}

			if (this.getIsRejectt(ds, orderdate1, loge)) {
				// 满座
				out
						.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>full</result></root>");
				return null;
			}
			if (ds.getType().intValue() == 1) {
				int ordnum = 1;
				try {
					ordnum = Integer.parseInt(num);
				} catch (Exception ee) {
					sbf.append("<result>-1</result></root>");
					out.print(sbf.toString());
					return null;
				}

				sbf.append("<result>"
						+ this.getShopService().getPrice(ds, date, logetype,
								ordnum) + "</result><des>"
						+ this.getShopService().getPriceDes(ds, date, logetype)
						+ "</des></root>");
				out.print(sbf.toString());
			} else if (ds.getType().intValue() == 5) {
				String hourfrom = request.getParameter("hourfrom");
				String hourto = request.getParameter("hourto");
				sbf.append("<result>"
						+ this.getShopService().getPrice1(ds, orderdate1,
								Integer.parseInt(hourfrom),
								Integer.parseInt(hourto)) + "</result></root>");
				out.print(sbf.toString());
			} else if (ds.getType().intValue() == 2) {
				sbf.append("<result>"
						+ this.getShopService().getPrice(ds, date, logetype, 1)
						+ "</result><des>"
						+ this.getShopService().getPriceDes(ds, date, logetype)
						+ "</des></root>");
				out.print(sbf.toString());
			}

			return null;
		} catch (Exception e) {
			sbf.append("<result>10.0</result></root>");
			out.print(sbf.toString());

			e.printStackTrace();
			return null;
		}
	}

	// 商品类获取价格
	public ActionForward getprice1(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {
			String date = request.getParameter("date");

			DdShopgoods dsg = this.getDdGoodDAO().findById(
					Integer.parseInt(request.getParameter("sid")));
			DdShop ds = this.getDdShopDAO().findById(dsg.getShopid());
			if (dsg == null) {
				sbf.append("<result>0</result></root>");
				out.print(sbf.toString());
				return null;
			}
			if (dsg.getStyleType().intValue() == 138) {// 蛋糕
				String selectsize = request.getParameter("selectsize");
				int size = Integer.parseInt(selectsize);
				if (size == 6) {
					sbf.append("<result>-1</result><des>测试</des></root>");
				} else if (size == 8) {
					sbf.append("<result>-1</result><des>测试</des></root>");
				} else if (size == 10) {
					sbf.append("<result>-1</result><des>测试</des></root>");
				} else {
					sbf.append("<result>-1</result><des>测试</des></root>");
				}
			} else {// 非蛋糕

				sbf.append("<result>"
						+ this.getShopService().getPrice2(ds, dsg, date)
						+ "</result><des>"
						+ this.getShopService().getPriceDes2(ds, dsg, date)
						+ "</des></root>");

			}

			out.print(sbf.toString());

			return null;
		} catch (Exception e) {
			sbf.append("<result>10.0</result></root>");
			out.print(sbf.toString());

			e.printStackTrace();
			return null;
		}
	}

	// 餐厅类商品获取价格
	// 目前就国香馆
	// 订菜系统
	// 1:根据shopid和菜名获取价格并乘以预付款比例系数返回
	// 2:预付款在最后生成订单时候验算一遍
	public ActionForward getprice2(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {
			int shopid = Integer.parseInt(request.getParameter("shopid"));
			String caiming = request.getParameter("caiming");
			List list = this.getDdGoodDAO().findByShopAndName(shopid, caiming);
			DdShopgoods dsg = (DdShopgoods) list.get(0);
			float scale = 20;
			sbf.append("<result>" + ((int) (dsg.getPrice() * scale / 100F))
					+ "</result></root>");

			out.print(sbf.toString());

			return null;
		} catch (Exception e) {
			sbf.append("<result>0</result></root>");
			out.print(sbf.toString());

			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findrestaurant(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		ServletContext application = servlet.getServletContext();
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		String ipport = request.getRemoteAddr() + request.getRemotePort();
		if (application.getAttribute(ipport) == null) {
			application.setAttribute(ipport, System.currentTimeMillis());
		} else {
			if ((System.currentTimeMillis() - (Long) application
					.getAttribute(ipport)) < REFLASH) {
				out
						.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>-3</error></root>");
				return null;
			} else {
				application.setAttribute(ipport, System.currentTimeMillis());
			}
		}
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");

		try {
			this.getShopService().findrestaurant(request, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findrestaurant2(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		ServletContext application = servlet.getServletContext();
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();

		StringBuffer sbf = new StringBuffer("{\"total\":");

		try {
			String name = request.getParameter("name");
			if (name == null || name.length() < 2) {
				out.print("{\"total\":-1,\"msg\":\"请输入店名!\"}");
				return null;
			}
			List list = this.getDdShopDAO().findByName(name);
			sbf.append(list.size()+",\"shops\":[");
			for (int i = 0; i < list.size(); i++) {
				
				DdShop ds = (DdShop) list.get(i);
				int hot = ds.getHot();
				String discountvalue = "";
				if (ds.getDiscount() != null && ds.getDiscount() > 0) {
					discountvalue = ds.getDiscount() + "折";
				}
				String stylevalue = "外送,自取";
				if(ds.getIsbooking().intValue()==1){
					stylevalue = ds.getStylevalue();
				}
				if(i==0){
					sbf.append("{\"id\":\""
							+ ds.getId()
							+ "\",\"name\":\""
							+ ds.getName()
							+ "\",\"issend\":\""
							+ ds.getIssend()
							+ "\",\"isbooking\":\""
							+ ds.getIsbooking()
							+ "\",\"iscoupon\":\""
							+ ds.getIscoupon()
							+ "\",\"wifi\":\""
							+ ds.getWifi()
							+ "\",\"visa\":\""
							+ ds.getVisa()
							+ "\",\"parking\":\""
							+ (ds.getPark()==-1?"0":"1")
							+ "\",\"address\":\""
							+ ds.getAddress() + "\",\"url\":\"" + ds.getUrl() + "\",\"discountvalue\":\""
							+ discountvalue + "\",\"stylevalue\":\""+stylevalue+"\",\"hot\":\""+hot+"\"}");
				}else{
					sbf.append(",{\"id\":\""
							+ ds.getId()
							+ "\",\"name\":\""
							+ ds.getName()
							+ "\",\"issend\":\""
							+ ds.getIssend()
							+ "\",\"isbooking\":\""
							+ ds.getIsbooking()
							+ "\",\"iscoupon\":\""
							+ ds.getIscoupon()
							+ "\",\"wifi\":\""
							+ ds.getWifi()
							+ "\",\"visa\":\""
							+ ds.getVisa()
							+ "\",\"parking\":\""
							+ (ds.getPark()==-1?"0":"1")
							+ "\",\"address\":\""
							+ ds.getAddress() + "\",\"url\":\"" + ds.getUrl() + "\",\"discountvalue\":\""
							+ discountvalue + "\",\"stylevalue\":\""+stylevalue+"\",\"hot\":\""+hot+"\"}");
				}
				
			}
			sbf.append("]}");
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findentertainment(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		ServletContext application = servlet.getServletContext();
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		String ipport = request.getRemoteAddr() + request.getRemotePort();
		if (application.getAttribute(ipport) == null) {
			application.setAttribute(ipport, System.currentTimeMillis());
		} else {
			if ((System.currentTimeMillis() - (Long) application
					.getAttribute(ipport)) < REFLASH) {
				out
						.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>-3</error></root>");
				return null;
			} else {
				application.setAttribute(ipport, System.currentTimeMillis());
			}
		}
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");

		try {
			this.getShopService().findentertainment(request, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findhotel(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		ServletContext application = servlet.getServletContext();
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		String ipport = request.getRemoteAddr() + request.getRemotePort();
		if (application.getAttribute(ipport) == null) {
			application.setAttribute(ipport, System.currentTimeMillis());
		} else {
			if ((System.currentTimeMillis() - (Long) application
					.getAttribute(ipport)) < REFLASH) {
				out
						.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>-3</error></root>");
				return null;
			} else {
				application.setAttribute(ipport, System.currentTimeMillis());
			}
		}
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");

		try {
			this.getShopService().findhotel(request, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findres(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		response.setContentType("text/text;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer("");
		try {
			DdShopDAO dsd = (DdShopDAO) this.getBean("DdShopDAO");
			String posx1 = request.getParameter("x1");
			String posx2 = request.getParameter("x2");
			String posy1 = request.getParameter("y1");
			String posy2 = request.getParameter("y2");
			List list = dsd.findAllShopByPos(posx1, posy1, posx2, posy2);
			for (int i = 0; i < list.size(); i++) {
				DdShop dd = (DdShop) list.get(i);
				sbf.append("<a onclick=\"zoomTo(" + dd.getPosx() + ","
						+ dd.getPosy() + ")\">" + dd.getName() + "</a></br>");
			}
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out.print("");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward finddelivery(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		response.setContentType("text/text;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer("");
		try {
			DdDeliveryDAO dddao = (DdDeliveryDAO) this.getBean("DdDeliveryDAO");
			String posx1 = request.getParameter("x1");
			String posx2 = request.getParameter("x2");
			String posy1 = request.getParameter("y1");
			String posy2 = request.getParameter("y2");
			List list = dddao.findAllDelvery(posx1, posy1, posx2, posy2);
			for (int i = 0; i < list.size(); i++) {
				DdDelivery dd = (DdDelivery) list.get(i);
				sbf.append("<a onclick=\"zoomTo(" + dd.getPosx() + ","
						+ dd.getPosy() + ")\">" + dd.getName() + "</a></br>");
			}
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out.print("");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward finddelivery2(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		response.setContentType("text;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer("");
		try {
			DdDeliveryDAO dddao = (DdDeliveryDAO) this.getBean("DdDeliveryDAO");
			String posx1 = request.getParameter("x1");
			String posx2 = request.getParameter("x2");
			String posy1 = request.getParameter("y1");
			String posy2 = request.getParameter("y2");
			List list = dddao.findAllDelvery(posx1, posy1, posx2, posy2);

			String contexts = "";
			for (int i = 0; i < list.size(); i++) {

				DdDelivery dd = (DdDelivery) list.get(i);
				String menustr = "<ul>";
				List menu = dddao.findMenuByID(dd.getId());
				for (int j = 0; j < menu.size(); j++) {
					DdDeliveryMenu dm = (DdDeliveryMenu) menu.get(j);
					menustr = menustr + "<li>" + dm.getMenuname() + " "
							+ dm.getPrice() + "</li>";
				}
				menustr = menustr + "</ul>";
				sbf.append("var point = new BMap.Point(" + dd.getPosx() + ","
						+ dd.getPosy() + ");");
				sbf.append("m" + dd.getId() + "= new BMap.Marker(point);");
				sbf.append(" m" + dd.getId() + ".setTitle('" + dd.getName()
						+ "');");
				sbf.append("var s" + dd.getId() + " =\"<h4 >" + dd.getName()
						+ "&nbsp;&nbsp;&nbsp;电话:" + dd.getPhone() + "</h4><h6>"
						+ dd.getDescription() + "</h6><div  class='mapos'>"
						+ menustr + "</div>\";");
				sbf.append(" i" + dd.getId() + " = new BMap.InfoWindow(s"
						+ dd.getId() + ");");
				sbf.append(" m" + dd.getId()
						+ ".addEventListener(\"click\", function(){");
				sbf.append("this.openInfoWindow(i" + dd.getId() + ");");
				sbf.append("});");
				sbf.append("map.addOverlay(m" + dd.getId() + ");");
				contexts = contexts + "<a onclick='openinfo(" + dd.getId()
						+ ")'>" + dd.getName() + "</a></br>";
				// sbf.append("contextshtml=contextshtml+"<a
				// onclick=\"openinfo("+dd.getPosx()+","+dd.getPosy()+",'"+dd.getName()+"')\">"+dd.getName()+"</a></br>\"");

			}

			sbf.append("$(\"#contexts\").html(\"" + contexts + "\");");
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out.print("");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward finddelivery3(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		response.setContentType("text/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer("[");
		try {
			DdDeliveryDAO dddao = (DdDeliveryDAO) this.getBean("DdDeliveryDAO");
			String posx1 = request.getParameter("x1");
			String posx2 = request.getParameter("x2");
			String posy1 = request.getParameter("y1");
			String posy2 = request.getParameter("y2");
			List list = dddao.findAllDelvery(posx1, posy1, posx2, posy2);

			String contexts = "";
			for (int i = 0; i < list.size(); i++) {

				DdDelivery dd = (DdDelivery) list.get(i);
				String menustr = "<ul>";
				List menu = dddao.findMenuByID(dd.getId());
				for (int j = 0; j < menu.size(); j++) {
					DdDeliveryMenu dm = (DdDeliveryMenu) menu.get(j);
					menustr = menustr + "<li>" + dm.getMenuname() + " "
							+ dm.getPrice() + "</li>";
				}
				menustr = menustr + "</ul>";
				if (i == 0) {
					sbf.append("{\"id\":\"" + dd.getId() + "\",\"name\":\""
							+ dd.getName() + "\",\"px\":\"" + dd.getPosx()
							+ "\",\"py\":\"" + dd.getPosy() + "\",\"phone\":\""
							+ dd.getPhone() + "\",\"des\":\""
							+ dd.getDescription() + "\",\"menu\":\"" + menustr
							+ "\"}");
				} else {
					sbf.append(",{\"id\":\"" + dd.getId() + "\",\"name\":\""
							+ dd.getName() + "\",\"px\":\"" + dd.getPosx()
							+ "\",\"py\":\"" + dd.getPosy() + "\",\"phone\":\""
							+ dd.getPhone() + "\",\"des\":\""
							+ dd.getDescription() + "\",\"menu\":\"" + menustr
							+ "\"}");

				}
				// sbf.append("var point = new BMap.Point("+dd.getPosx()+","+dd.getPosy()+");");
				// sbf.append("m"+dd.getId()+"= new BMap.Marker(point);");
				// sbf.append(" m"+dd.getId()+".setTitle('"+dd.getName()+"');");
				// sbf.append("var s"+dd.getId()+" =\"<h4 >"+dd.getName()+"&nbsp;&nbsp;&nbsp;电话:"+dd.getPhone()+"</h4><h6>"+dd.getDescription()+"</h6><div  class='mapos'>"+menustr+"</div>\";");
				// sbf.append(" i"+dd.getId()+" = new BMap.InfoWindow(s"+dd.getId()+");");
				// sbf.append(" m"+dd.getId()+".addEventListener(\"click\", function(){");
				// sbf.append("this.openInfoWindow(i"+dd.getId()+");");
				// sbf.append("});");
				// sbf.append("map.addOverlay(m"+dd.getId()+");");
				// contexts=contexts+"<a onclick='openinfo("+dd.getId()+")'>"+dd.getName()+"</a></br>";

			}
			sbf.append("]");
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out.print("");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	// reloadgoogle
	public ActionForward reloadgoogle(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		response.setContentType("text/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer("[");
		try {

			List list = this.getDdShopDAO().findNoGoogle(8);
			int count = 0;
			for (int i = 0; i < list.size(); i++) {
				DdShop ds = (DdShop) list.get(i);
				if (count == 0) {
					sbf.append("{\"id\":\"" + ds.getId() + "\",\"name\":\""
							+ ds.getName() + "\",\"px\":\"" + ds.getPosx()
							+ "\",\"py\":\"" + ds.getPosy()
							+ "\",\"address\":\"" + ds.getAddress() + "\"}");
				} else {
					sbf.append(",{\"id\":\"" + ds.getId() + "\",\"name\":\""
							+ ds.getName() + "\",\"px\":\"" + ds.getPosx()
							+ "\",\"py\":\"" + ds.getPosy()
							+ "\",\"address\":\"" + ds.getAddress() + "\"}");
				}
				count++;
			}
			sbf.append("]");
			out.println(sbf.toString());
			out.flush();
			return null;
		} catch (Exception e) {
			out.print("");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward reportgoogle(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer("[");
		try {
			int sid = Integer.parseInt(request.getParameter("sid"));
			String gx = request.getParameter("gx");
			String gy = request.getParameter("gy");
			DdShop ds = this.getDdShopDAO().findById(sid);
			ds.setPosx_g(gx);
			ds.setPosy_g(gy);
			this.getDdShopDAO().saveOrUpdate(ds);

			out.println("更新成功!");
			out.flush();
			return null;
		} catch (Exception e) {
			out.print("更新失败!");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findMapShopApp(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		response.setContentType("text/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer("[");
		try {
			String callback = request.getParameter("jsoncallback");
			String posx1 = request.getParameter("x1");
			String posx2 = request.getParameter("x2");
			String posy1 = request.getParameter("y1");
			String posy2 = request.getParameter("y2");
			List list = this.getDdShopDAO().findAllByPos(posx1, posy1, posx2,
					posy2, "0", "0", "0", "0", "0", "1");
			int count = 0;
			for (int i = 0; i < list.size(); i++) {
				DdShop ds = (DdShop) list.get(i);

				if (count == 0) {
					sbf
							.append("{\"id\":\""
									+ ds.getId()
									+ "\",\"name\":\""
									+ ds.getName()
									+ "\",\"px\":\""
									+ ds.getPosx()
									+ "\",\"py\":\""
									+ ds.getPosy()
									+ "\",\"phone\":\""
									+ ds.getPhone()
									+ "\",\"des\":\""
									+ ds.getDescription().replace("\r\n", "")
											.replace("\r", "")
											.replace("\n", "")
											.replace("\t", "")
									+ "\",\"url\":\"" + ds.getUrl() + "\"}");
				} else {
					sbf
							.append(",{\"id\":\""
									+ ds.getId()
									+ "\",\"name\":\""
									+ ds.getName()
									+ "\",\"px\":\""
									+ ds.getPosx()
									+ "\",\"py\":\""
									+ ds.getPosy()
									+ "\",\"phone\":\""
									+ ds.getPhone()
									+ "\",\"des\":\""
									+ ds.getDescription().replace("\r\n", "")
											.replace("\r", "")
											.replace("\n", "")
											.replace("\t", "")
									+ "\",\"url\":\"" + ds.getUrl() + "\"}");
				}
				count++;
			}
			sbf.append("]");
			out.println(callback + "(" + sbf.toString() + ")");
			out.flush();
			return null;
		} catch (Exception e) {
			out.print("");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findMapShop(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		response.setContentType("text/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer("[");
		try {
			String posx1 = request.getParameter("x1");
			String posx2 = request.getParameter("x2");
			String posy1 = request.getParameter("y1");
			String posy2 = request.getParameter("y2");
			String shopname = request.getParameter("shopname");
			String sending = request.getParameter("sending");
			String booking = request.getParameter("booking");
			String discount = request.getParameter("discount");
			String shopstyle = request.getParameter("shopstyle");
			String shopcost = request.getParameter("shopcost");
			String test = request.getParameter("test");
			int count = 0;
			Hashtable ht = new Hashtable();
			if (shopname != null && shopname.length() > 1
					&& !shopname.equals("餐厅名")) {
				List list = this.getDdShopDAO().findAllByShopname(shopname,
						test);
				for (int i = 0; i < list.size(); i++) {
					DdShop ds = (DdShop) list.get(i);
					ht.put(ds.getId(), ds.getId());
					if (count == 0) {
						sbf.append("{\"id\":\""
								+ ds.getId()
								+ "\",\"name\":\""
								+ ds.getName()
								+ "\",\"px\":\""
								+ ds.getPosx()
								+ "\",\"py\":\""
								+ ds.getPosy()
								+ "\",\"issend\":\""
								+ ds.getIssend()
								+ "\",\"isbooking\":\""
								+ ds.getIsbooking()
								+ "\",\"iscoupon\":\""
								+ ds.getIscoupon()
								+ "\",\"phone\":\""
								+ ds.getPhone()
								+ "\",\"des\":\""
								+ ds.getDescription().replace("\r\n", "")
										.replace("\r", "").replace("\n", "")
										.replace("\t", "") + "\",\"url\":\""
								+ ds.getUrl() + "\"}");
					} else {
						sbf.append(",{\"id\":\""
								+ ds.getId()
								+ "\",\"name\":\""
								+ ds.getName()
								+ "\",\"px\":\""
								+ ds.getPosx()
								+ "\",\"py\":\""
								+ ds.getPosy()
								+ "\",\"issend\":\""
								+ ds.getIssend()
								+ "\",\"isbooking\":\""
								+ ds.getIsbooking()
								+ "\",\"iscoupon\":\""
								+ ds.getIscoupon()
								+ "\",\"phone\":\""
								+ ds.getPhone()
								+ "\",\"des\":\""
								+ ds.getDescription().replace("\r\n", "")
										.replace("\r", "").replace("\n", "")
										.replace("\t", "") + "\",\"url\":\""
								+ ds.getUrl() + "\"}");
					}
					count++;
				}
			}

			List list = this.getDdShopDAO().findAllByPos(posx1, posy1, posx2,
					posy2, sending, booking, discount, shopstyle, shopcost,
					test);
			for (int i = 0; i < list.size(); i++) {
				DdShop ds = (DdShop) list.get(i);
				if (ht.containsKey(ds.getId())) {
					continue;
				}
				if (count == 0) {
					sbf
							.append("{\"id\":\""
									+ ds.getId()
									+ "\",\"name\":\""
									+ ds.getName()
									+ "\",\"px\":\""
									+ ds.getPosx()
									+ "\",\"py\":\""
									+ ds.getPosy()
									+ "\",\"issend\":\""
									+ ds.getIssend()
									+ "\",\"isbooking\":\""
									+ ds.getIsbooking()
									+ "\",\"iscoupon\":\""
									+ ds.getIscoupon()
									+ "\",\"phone\":\""
									+ ds.getPhone()
									+ "\",\"des\":\""
									+ ds.getDescription().replace("\r\n", "")
											.replace("\r", "")
											.replace("\n", "")
											.replace("\t", "")
									+ "\",\"url\":\"" + ds.getUrl() + "\"}");
				} else {
					sbf
							.append(",{\"id\":\""
									+ ds.getId()
									+ "\",\"name\":\""
									+ ds.getName()
									+ "\",\"px\":\""
									+ ds.getPosx()
									+ "\",\"py\":\""
									+ ds.getPosy()
									+ "\",\"issend\":\""
									+ ds.getIssend()
									+ "\",\"isbooking\":\""
									+ ds.getIsbooking()
									+ "\",\"iscoupon\":\""
									+ ds.getIscoupon()
									+ "\",\"phone\":\""
									+ ds.getPhone()
									+ "\",\"des\":\""
									+ ds.getDescription().replace("\r\n", "")
											.replace("\r", "")
											.replace("\n", "")
											.replace("\t", "")
									+ "\",\"url\":\"" + ds.getUrl() + "\"}");
				}
				count++;
			}
			sbf.append("]");
			out.print(sbf.toString());
			out.flush();
			return null;
		} catch (Exception e) {
			out.print("");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findsport(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		ServletContext application = servlet.getServletContext();
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		String ipport = request.getRemoteAddr() + request.getRemotePort();
		if (application.getAttribute(ipport) == null) {
			application.setAttribute(ipport, System.currentTimeMillis());
		} else {
			if ((System.currentTimeMillis() - (Long) application
					.getAttribute(ipport)) < REFLASH) {
				out
						.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>-3</error></root>");
				return null;
			} else {
				application.setAttribute(ipport, System.currentTimeMillis());
			}
		}
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");

		try {
			this.getShopService().findsport(request, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward findshopping(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		ServletContext application = servlet.getServletContext();
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		String ipport = request.getRemoteAddr() + request.getRemotePort();
		if (application.getAttribute("ipport") == null) {
			application.setAttribute(ipport, System.currentTimeMillis());
		} else {
			if ((System.currentTimeMillis() - (Long) application
					.getAttribute(ipport)) < REFLASH) {
				out
						.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>-3</error></root>");
				return null;
			} else {
				application.setAttribute(ipport, System.currentTimeMillis());
			}
		}
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");

		try {
			this.getShopService().findshopping(request, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward firstpageshop(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		ServletContext application = servlet.getServletContext();
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		String ipport = request.getRemoteAddr() + request.getRemotePort();
		if (application.getAttribute(ipport) == null) {
			application.setAttribute(ipport, System.currentTimeMillis());
		} else {
			if ((System.currentTimeMillis() - (Long) application
					.getAttribute(ipport)) < REFLASH) {
				out
						.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>-3</error></root>");
				return null;
			} else {
				application.setAttribute(ipport, System.currentTimeMillis());
			}
		}
		try {
			String type = request.getParameter("type");
			if (type == null) {
				sbf.append("<error>-2</error></root>");
				out.print(sbf.toString());
				return null;
			}
			List list = this.getDdShopDAO().findFirstPage(
					Integer.parseInt(type));
			sbf.append("<shops>");
			for (int i = 0; i < list.size(); i++) {
				Object[] obj = (Object[]) list.get(i);
				DdFirstPage dfp = (DdFirstPage) obj[0];
				DdShop ds = (DdShop) obj[1];
				sbf.append("<shop id=\"" + ds.getId() + "\" shopname=\""
						+ ds.getName() + "\" url=\"" + dfp.getUrl()
						+ "\"  remark=\"" + dfp.getRemark() + "\" isbooking=\""
						+ ds.getIsbooking() + "\" issend=\"" + ds.getIssend()
						+ "\" />");
			}
			sbf.append("</shops></root>");
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward newgood(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {
			DdShop ds = this.getDdShopDAO().findById(
					Integer.parseInt(request.getParameter("shopid")));
			if (ds == null) {
				sbf.append("<result>2</result></root>");
				return null;
			}
			DdShopgoods dsg = new DdShopgoods();
			this.getShopService().newGood(request, dsg, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward product(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {
			DdShopgoods dsg = this.getDdGoodDAO().findById(
					Integer.parseInt(request.getParameter("goodid")));
			if (dsg == null) {
				sbf.append("<result>2</result></root>");
				return null;
			}

			this.getShopService().goodInfo(request, dsg, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward editgood(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {

			DdShopgoods dsg = this.getDdGoodDAO().findById(
					Integer.parseInt(request.getParameter("goodid")));
			if (dsg == null) {
				sbf.append("<result>2</result></root>");
				return null;
			}
			this.getShopService().newGood(request, dsg, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward delgood(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {

			DdShop ds = this.getDdShopDAO().findById(
					Integer.parseInt(request.getParameter("shopid")));
			if (ds == null) {
				sbf.append("<result>2</result></root>");
				return null;
			}
			this.getShopService().editShop(request, ds, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward addfirstpage(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {
			this.getShopService().addfirstpage(request, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward removefirstpage(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {
			this.getShopService().removefirstpage(request, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward listfirstpage(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		HttpSession session = request.getSession();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		PrintWriter out = response.getWriter();
		try {

			this.getShopService().listfirstpage(request, sbf);
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * Method execute 上传照片
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward upload(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			MainForm mainForm = (MainForm) form;
			FormFile file = mainForm.getFile();// 图片对象
			// String rootpath = request.getRealPath("");// 根路径流
			String typeid = request.getParameter("typeid");// 商家ID
			String imageid = request.getParameter("imageid");// 第几张图片
			// HcPtdcacvUser user = (HcPtdcacvUser)
			// request.getSession().getAttribute(
			// "user");
			String temp = "\\upload\\";// 添加文字的图片路径
			String userpath = request.getRealPath("") + temp;// 绝对路径
			@SuppressWarnings("unused")
			File file1 = new File(userpath);// 根路径
			if (!file1.exists()) {
				new File(userpath).mkdir(); // 创建路径
			}
			userpath += "" + typeid;// 商家路径
			file1 = new File(userpath);
			if (!file1.exists()) {
				new File(userpath).mkdir(); // 创建路径
			}
			if (file != null && file.getFileSize() > 0) {// 上传

				String filepath = new UpFile().uploadfile(userpath + "\\pic"
						+ imageid + ".jpg", file, imageid);
				if (filepath != null && filepath.trim().length() > 0) {
					ShopService ss = this.getShopService();// 获取商家Servcie
					DdShopDAO dsd = ss.getDdShopDAO();
					DdShop ds = ss.getDdShopDAO().findById(
							Integer.parseInt(request.getParameter("typeid")));
					try {
						if (imageid != null && imageid.trim().length() > 0) {
							if (imageid.equals("1")) {// 判断是那张图片
								ds.setPic1("1");
							}
							if (imageid.equals("2")) {
								ds.setPic2("1");
							}
							if (imageid.equals("3")) {
								ds.setPic3("1");
							}
							if (imageid.equals("4")) {
								ds.setPic4("1");
							}
							if (imageid.equals("5")) {
								ds.setPic5("1");
							}
							if (imageid.equals("6")) {
								ds.setPic6("1");
							}
							if (imageid.equals("7")) {
								ds.setPic7("1");
							}
							if (imageid.equals("8")) {
								ds.setPic8("1");
							}
							this.getDdShopDAO().saveOrUpdate(ds);
							// ss.newShop(request, ds, new StringBuffer());
						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					request.setAttribute("msg", "上传成功");
				}
			}
			return mapping.findForward("upload");
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
